package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.service.FileUploadService;
import io.minio.*;
import io.minio.errors.MinioException;
import io.swagger.annotations.Api;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;

/**
 * @Author atguigu-mqx
 * @Description TODO
 * @Date 2023/8/19 9:44
 * @Version 1.0
 */
@Api(tags = "文件上传")
@RestController
@RequestMapping("/admin/product")
@RefreshScope //  nacos 配置文件中如果有数据修改，可以让代码中的数据进行热部署.
public class FileUpLoadController {
    /*
    minio:
      endpointUrl: http://192.168.200.130:9000
      accessKey: admin
      secreKey: admin123456
      bucketName: test
     */
    @Autowired
    private FileUploadService fileUploadService;

    /**
     * 文件上传的时候，方法的参数名称必须file
     * @param file
     * @return
     */
    @PostMapping("/fileUpload")
    public Result fileUpload(MultipartFile file){
        //  调用服务层方法
        return fileUploadService.uploadFile(file);
    }
}
